use super::{AgentType, BehaviorRules};
use serde_json::Value;
use std::collections::HashMap;

/// 经济智能体核心实现
#[derive(Debug, Clone)]
pub struct EconomicAgent {
    pub id: u32,
    pub agent_type: AgentType,
    pub resources: f64,
    pub behavior: BehaviorRules,
    pub history: Vec<AgentAction>,
}

#[derive(Debug, Clone)]
pub struct AgentAction {
    pub action_type: ActionType,
    pub amount: f64,
    pub timestamp: i64,
}

#[derive(Debug, Clone)]
pub enum ActionType {
    Produce,
    Consume,
    Invest,
    Tax,
    Regulate,
}

impl EconomicAgent {
    /// 创建新经济智能体
    pub fn new(id: u32, agent_type: AgentType, behavior: BehaviorRules) -> Self {
        EconomicAgent {
            id,
            agent_type,
            resources: 1000.0,
            behavior,
            history: Vec::new(),
        }
    }

    /// 执行消费行为
    pub fn consume(&mut self, amount: f64) -> Result<f64, super::error::AgentError> {
        if amount > self.resources {
            return Err(super::error::AgentError::InsufficientResources);
        }
        self.resources -= amount;
        self.history.push(AgentAction {
            action_type: ActionType::Consume,
            amount,
            timestamp: chrono::Local::now().timestamp(),
        });
        Ok(self.resources)
    }

    /// 执行生产行为
    pub fn produce(&mut self, amount: f64) -> f64 {
        self.resources += amount;
        self.history.push(AgentAction {
            action_type: ActionType::Produce,
            amount,
            timestamp: chrono::Local::now().timestamp(),
        });
        self.resources
    }
}